package org.example;

import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;

public class Test2 {
    //leetcode 2208 将数组和减半的最少操作数 https://leetcode.cn/problems/minimum-operations-to-halve-array-sum/description/
    public int halveArray(int[] nums) {
        double sum = 0;
        PriorityQueue<Double> heap = new PriorityQueue<>(new Comparator<Double>() {
            @Override
            public int compare(Double o1, Double o2) {
                return o2.compareTo(o1);
            }
        });
        for (int n : nums) {
            heap.add(n * 1.0);
            sum += n;
        }
        sum /= 2;
        int count = 0;
        for (int i = 0; i < nums.length; i++) {
            if (sum <= 0) break;
            double tmp = heap.poll();
            sum -= tmp / 2.0;
            heap.add(tmp / 2.0);
            count++;
        }

        return count;
    }

    public static void main(String[] args) {
        Test2 test2 = new Test2();
        int[] arr = {5,19,8,1};
        test2.halveArray(arr);
        System.out.println(555);
    }
}
